package scau.erps.view.dashboard;

import java.util.List;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

import scau.erps.app.Erps;
import scau.erps.entity.Extrascore;
import scau.erps.service.ExtrascoreService;
import scau.erps.service.impl.ExtrascoreServiceImpl;

/**
 * 综合分数折线图
 * @author DCJ
 * 
 */
public class ScoreChart{	
	/**
	 * 得到图片
	 * @return
	 */
	public static JFreeChart getChart(){
		JFreeChart chart = createChart(createDataset());
		return chart;
	}
	/**
	 * 数据
	 */
	public static DefaultCategoryDataset createDataset() {
		DefaultCategoryDataset linedataset = new DefaultCategoryDataset();
		// 曲线名称
		String series = "综合分数";
        ExtrascoreService extrascoreService=Erps.getIocInstance().get(ExtrascoreServiceImpl.class);
	 	List<Extrascore> list=extrascoreService.getExtrascores(Erps.getSand().getTeam_Id());
		for (Extrascore extrascore: list){
			int avgort=extrascore.getAvgort();
			linedataset.addValue(avgort, series, extrascore.getYear());
		}

		return linedataset;
	}
	/**
	 * 绘制折线
	 */
	public static JFreeChart createChart(DefaultCategoryDataset linedataset) {
		  //createLineChart 参数依次为：标题，横坐标标题，纵坐标标题，数据，方向，图例，工具，超链接
		  JFreeChart chart = ChartFactory.createLineChart("历年综合分数", "年份", "得分", linedataset, PlotOrientation.VERTICAL, true, true, false);
		  return chart;
		 }
	}
